package com.user.chris.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.common.chris.util.SnowflakeIdWorker;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.user.chris.dao.UserDAO;
import com.user.chris.entity.po.UserPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserDAO userDAO;

    public PageInfo<UserPO> listUser() {
        PageHelper.startPage(1,1);
        List<UserPO> userPOS = userDAO.selectList(null);
        PageInfo<UserPO> pageInfo = new PageInfo<>(userPOS);
        return pageInfo;
    }

    @Transactional(rollbackFor = Exception.class)
    public Integer add() {
        long l = SnowflakeIdWorker.nextId();
        UserPO userPO = new UserPO();
        userPO.setUserId(l);
        userPO.setPassword("123");
        userPO.setUserName("雷恩加尔");
        userPO.setZb("短匕");
        int insert = userDAO.insert(userPO);
        return insert;
    }


    public PageInfo<UserPO> listUser05() {
        PageHelper.startPage(1,10);
        QueryWrapper<UserPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("user_name", "哈");
        List<UserPO> userPOS = userDAO.selectList(queryWrapper);
        PageInfo<UserPO> pageInfo = new PageInfo<>(userPOS);
        return pageInfo;
    }


}
